package com.rush.manageepac.service.impl;

import com.rush.manageepac.dao.NewsDao;
import com.rush.manageepac.entity.News;
import com.rush.manageepac.service.intf.NewsService;
import com.rush.manageepac.util.StringUtil;
import com.rush.manageepac.vo.PageBean;
import com.rush.manageepac.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class NewsServiceImpl implements NewsService {
    @Autowired
    private NewsDao dao;
    @Override
    public R save(News news) {
        System.out.println(news);
        if(dao.save(news)>0){
            return R.ok();
        }else {
            return R.fail();
        }
    }


    @Override
    public R delete(int id) {
        if(dao.delete(id)>0){
            return R.ok();
        }else {
            return R.fail();
        }
    }

    @Override
    public PageBean selectPage(String title, int page, int limit) {
//        if(name!=null && name.length()>0){
        if(StringUtil.isNotEmpty(title)){
            title="%"+title+"%";
        }else{
            title=null;
        }
        int start=(page-1)*limit;

        return PageBean.ok(dao.selectCount(title),dao.selectPage(title,start,limit));
    }

    @Override
    public R update(News news) {
        if(dao.update(news)>0){
            return R.ok();
        }else {
            return R.fail();
        }
    }
}
